package com.atguigu.spzx.manager.controller;

import com.atguigu.spzx.manager.service.SysMenuService;
import com.atguigu.spzx.model.entity.system.SysMenu;
import com.atguigu.spzx.model.vo.common.Result;
import com.atguigu.spzx.model.vo.common.ResultCodeEnum;
import io.swagger.v3.oas.annotations.tags.Tag;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@Tag(name = "菜单接口")
@RestController
@RequestMapping(value = "/admin/system/sysMenu")
public class SysMenuController {
    @Autowired
    private SysMenuService sysMenuService;

    //查询所有菜单   层级实现
    @GetMapping("/findNodes")
    public Result<List<SysMenu>> findNodes() {
        List<SysMenu> list = sysMenuService.findNodes();
        return Result.build(list , ResultCodeEnum.SUCCESS) ;
    }
    //菜单添加
    @PostMapping("/save")
    public Result save(@RequestBody SysMenu sysMenu){
                sysMenuService.save(sysMenu);
        return Result.build(null , ResultCodeEnum.SUCCESS) ;
    }
    //菜单修改 todo 子菜单修改异常
    @PutMapping("/update")
    public Result updateById(@RequestBody SysMenu sysMenu){
        sysMenuService.update(sysMenu);
        return Result.build(null , ResultCodeEnum.SUCCESS) ;
    }
    //菜单删除
    @DeleteMapping("/removeById/{id}")
    public Result removeById(@PathVariable("id")long id){
        sysMenuService.removeById(id);
        return Result.build(null , ResultCodeEnum.SUCCESS) ;
    }


}
